﻿using System;
using System.IO;
using Business.Entity.Sped;
using NHibernate;

namespace Business.InformacoesIniciais
{
    public class DadosIniciaisCst
    {
        public static void Inicio(ISession session)
        {
            var dir = Environment.CurrentDirectory + "\\arquivos\\";
            var arqCstIcms = new StreamReader(dir + "cstIcms.txt");
            var arqCstPis = new StreamReader(dir + "cstPis.txt");
            var arqCstCofins = new StreamReader(dir + "cstCofins.txt");
            var lineCstIcms = "";
            var lineCstPis = "";
            var lineCstCofins = "";
            while (lineCstIcms != null)
            {
                lineCstIcms = arqCstIcms.ReadLine();
                if (lineCstIcms != null && !lineCstIcms.Equals(""))
                {
                    var split = lineCstIcms.Split(';');
                    var cst = new CST()
                    {
                        Codigo = split[0],
                        Descricao = "'"+ split[1] + "'", 
                        Origem = split[0].Substring(0,1)
                    };
                    session.Save(cst);
                }
            }
            while (lineCstPis != null)
            {
                lineCstPis = arqCstPis.ReadLine();
                if (lineCstPis != null && !lineCstPis.Equals(""))
                {
                    var split = lineCstPis.Split(';');
                    var cstPis = new CSTPis()
                    {
                        Cst = split[0],
                        Descricao = "'" + split[1] +"'"
                    };
                    session.Save(cstPis);
                }
            }
            while (lineCstCofins != null)
            {
                lineCstCofins = arqCstCofins.ReadLine();
                if (lineCstCofins != null && !lineCstCofins.Equals(""))
                {
                    var split = lineCstCofins.Split(';');
                    var cstCofins = new CSTCofins()
                    {
                        Codigo = split[0],
                        Descricao = "'" +split[1] + "'"
                    };
                    session.Save(cstCofins);
                }
            }
        }
    }
}
